<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>
        <c:if test="${empty(data.id)}">添加部门管理</c:if>
        <c:if test="${!empty(data.id)}">编辑部门管理</c:if>
    </title>
</head>

<body>

<div id="wrapper">
    <div class="gray-bg">
        <div class="row m-t-sm">
            <div class="col-lg-12">
                <ol class="breadcrumb f-fl">
                    <li>
                        <i class="fa fa-location-arrow"></i><a>部门管理管理</a>
                    </li>
                    <li class="active">
                        <strong>
                            <c:if test="${empty(peCenter.id)}">添加部门管理</c:if>
                            <c:if test="${!empty(peCenter.id)}">编辑部门管理</c:if>
                        </strong>
                    </li>
                </ol>
                <span class="navbar-right  m-r m-t-8"><a href="javascript:history.go(-1);" class="btn-primary btn-add "> <i class='fa fa-mail-reply'></i> 返回</a></span>
            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <form method="get" data-ajax="${ctx}/admin/ehm/dept/list" action="${ctx}/admin/ehm/dept/${method}"  class="form-horizontal" id="base_form">
                                <input  type="hidden" name="id" value="${data.id}"/>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>部门编号</label>
                                    <div class="col-sm-3">
                                        <input id="xmbh" type="text" class="form-control" onBlur="validate(this.value);" placeholder="编号" value="${data.sn}" name="sn" required >
                                        <span id="userText"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">部门名称</label>
                                    <div class="col-sm-3"><input type="text" class="form-control" placeholder="分类名称" value="${data.title}" name="title" required></div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-2">
                                        <button class="btn btn-primary" type="submit">保 存</button>
                                        <a href="javascript:history.go(-1);" class="btn btn-white ">  取消</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script>
    function validate(val) {
        var reg = /([\u4E00-\u9FA5])+/;//只要包含中文或者字母就提示

        if(val == '' || val == undefined){
            parent.layer.msg('请输入编码');
            return;
        }else if(reg.test(val)){
            flag = true;
            parent.layer.msg('不能输入中文');
            return;
        }else{
            $.ajax({
                method: "POST",
                url: "${ctx}/admin/ehm/dept/validations",
                data: {
                    validation:val,
                    id:id
                },
                dataType: "json",
                async: false,
                success: function(response) {
                    if (response.code == 0) {
                        if(response.msg == '该编码已被占用'){
                            parent.layer.msg('该编码已被占用,请重新输入编码');
                            flag = true;
                        }else{
                            flag = false;
                        }
                        console.log(response.msg);
                    }else{
                        flag = false;
                    }
                }
            });
        }

    }


</script>
</body>

</html>
